<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head th:include="common/common::header">

</head>
<body>
<div class="x-nav">
		<span class="layui-breadcrumb"> <a href="">首页</a> <a href="">演示</a>
			<a> <cite>导航元素</cite>
		</a> </span> <a class="layui-btn layui-btn-small"
                        style="line-height:1.6em;margin-top:3px;float:right"
                        href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">&#xe666</i>
</a>
</div>
<blockquote class="layui-elem-quote news_search" style="margin-top: 10px;height: 35px;">
    <form class="layui-form" action="">
        <div class="layui-inline" style="margin-left: -15px;">
            <label class="layui-form-label">订单状态:</label>
            <div class="layui-input-inline">
                <select name="status" id="status1">
                    <option value=""></option>
                    <option value="0">待处理</option>
                    <option value="1">正在处理</option>
                    <option value="2">已处理</option>
                </select>
            </div>
        </div>
        <div class="layui-inline" style="margin-left: -20px;">
            <label class="layui-form-label">申请人：</label>
            <div class="layui-input-inline"  >
                <input type="text" value="" placeholder="输入申请人姓名" id="repairName1"
                       class="layui-input search_input">
            </div>
        </div>
        <div class="layui-inline" style="margin-left: -20px;">
            <label class="layui-form-label">联系方式：</label>
            <div class="layui-input-inline"  >
                <input type="text" value="" placeholder="输入申请人电话" id="repairPhone1"
                       class="layui-input search_input">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i>查询</button>
        </div>

    </form>
    <div class="layui-inline">
        <div class="layui-form-mid layui-word-aux"></div>
    </div>
</blockquote>
<div class="layui-form links_list">
    <table  id="demo" lay-filter="test" class="layui-hide"></table>

</div>
<div class="x-body" style="display:none;" id="update">
    <form class="layui-form" id="addform" lay-filter="test1">
        <input id="id" name="id" style="display:none">
        <div class="layui-form-item">
            <label for="repairName" class="layui-form-label"> 报修人姓名 </label>
            <div class="layui-input-inline">
                <input type="text" id="repairName" name="repairName" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">
            <label for="repairAddr" class="layui-form-label"> 报修地址 </label>
            <div class="layui-input-inline">
                <input type="text" id="repairAddr" name="repairAddr"
                       autocomplete="off" class="layui-input" disabled>
            </div>

        </div>
        <div class="layui-form-item">
            <label for="repairPhone" class="layui-form-label"> 联系人 </label>
            <div class="layui-input-inline">
                <input type="text" id="repairPhone" name="repairPhone" required=""
                       lay-verify="number" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="repairTime" class="layui-form-label"> <span
                    class="x-red"></span>报修时间 </label>
            <div class="layui-input-inline">
                <input type="text" id="repairTime" name="repairTime" required=""
                       autocomplete="off" class="layui-input">
            </div>

        </div>
        <div class="layui-form-item layui-form-text">
            <label for="repairDesc" class="layui-form-label">报修描述 </label>
            <div class="layui-input-block">
					<textarea placeholder="请输入内容" id="repairDesc" name="repairDesc"
                              class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal">返回</button>

            </div>
        </div>
    </form>
</div>
<script type="text/html" id="changebar">
    <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
{{# if(d.status==0){ }}
    <a   class="layui-btn layui-btn-normal layui-btn-xs" lay-event="process">待处理</a>
 {{# } }}
    {{# if(d.status==1){ }}
    <a   class="layui-btn layui-btn-danger layui-btn-xs" lay-event="process">待确认</a>
    {{# } }}
    {{# if(d.status==2){ }}
    <a  class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="process">已完成</a>
    {{# } }}
</script>
<script type="text/html" id="status">
    {{# if(d.status==0){ }}
   <span class="layui-btn layui-btn-warm layui-btn-xs">待处理</span>
    {{# } }}
    {{# if(d.status==1){ }}
   <span class="layui-btn layui-btn-normal layui-btn-xs" >正在处理</span>
    {{# } }}
    {{# if(d.status==2){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs" >处理完成</span>
    {{# } }}
</script>

</body>
<script>
    layui.use([ 'table', 'layer','form', 'laytpl' ,'element'], function() {
        var table = layui.table;
        var element = layui.element;
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var element = layui.element;

        <!---------------------重载实现模糊查询---------------- -->
        form.on('submit(search)', function(data){
            var repairName = $("#repairName1").val();
            var repairPhone = $("#repairPhone1").val();
            var status=$("#status1").val();

            table.reload('allsel', {
                url : '/dangxia/repair/getAll',
                method : 'post',
                where : {
                    repairName : repairName,
                    repairPhone : repairPhone,
                    status:status
                }
            });

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


      <!--------------------  表格数据-------------------------->
        table.render({
            elem: '#demo',
            height: 312,
            id:'allsel',
            toolbar:true,
            url: '/dangxia/repair/getAll?status=0', //数据接口
            // page: true //开启分页
            limits:[2,5,10,20],
            limit:5,
            page:true,
            cols : [ [ //表头
                {
                    type:'checkbox',
                    fixed: 'left'
                }, {
                    field : 'id',
                    title : '编号',
                    sort : true
                }, {
                    field : 'repairAddr',
                    title : '维修地址'
                }, {
                    field : 'repairPhone',
                    title : '联系方式'
                }, {
                    field : 'repairTitle',
                    title : '标题',
                }, {
                    field : 'repairName',
                    title : '报修人姓名'
                }, {
                    field : 'repairTime',
                    title : '报修时间',
                    sort : true
                },
                {
                    field : 'status',
                    title : '订单状态',
                    templet:'#status',
                    align:'center'
                },
                {   field:'right',
                    title : '操作',
                    align : 'center',
                    toolbar : '#changebar'
                } ] ],
            initSort:{
                field:'id',
                type:'desc'
            },


        });
        <!------------------------------操作栏------------------- -->
        table.on('tool(test)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent === 'detail') { //查看
                $.post("/dangxia/repair/queryById", {
                    "id" : data.id,
                }, function(data) {
                    $("#id").val(data.id);
                    $("#repairName").val(data.repairName);
                    $("#repairAddr").val(data.repairAddr);
                    $("#repairPhone").val(data.repairPhone);
                    $("#repairDesc").val(data.repairDesc);
                    $("#repairTime").val(data.repairTime);

                });



                /*---------配置弹出层-------------*/
                layer.open({
                    type : 1,
                    title : '查看详情',

                    shade : [ 0.3, '#393D49' ],
                    maxmin : false,
                    shadeClose : false,
                    area : [ '450px', '350px' ],
                    content : $("#update")//这里需要公告查看子页面，传id在弹窗打开
                    ,
                    success : function(layero, index) {
                        console.log(layero, index);
                    }

                });
            }
            /*---------------另一个业务--------------------------*/
            else if (layEvent === 'process') { //处理
                    layer.confirm('确定处理吗', function(index) {
                        $.post("/dangxia/repair/updateState", {
                            "id" : data.id,
                            "status":data.status
                        }, function(res) {
                            console.log(res)
                            if (res.code== 0) {
                                layer.msg("处理完成",{icon:6,time:1000},function () {
                                    location.reload();
                                })
                                //location.reload();
                            }

                        });

                        layer.close(index);
                    });



            }
        });

    });
</script>
</html>